import api from "@/assets/js/api.js";
import sess from "@/assets/js/sess.js";
export default {
  state:{
    carList:[],
    loading:false,
    deleteStatus:0,
    // marketId:sess.get('userInfo').accountPropertyMap.marketId,
    tips:{
      type:'success',
      message:'删除成功'
    }
  },
  mutations:{
    getSystemCarList(state,value){
      state.carList = value;
    },
    changeLoading(state,value){
      state.loading = value;
    },
    changeDeleteStatus(state,value){
      state.deleteStatus += value;
    },
    changeTips(state,value){
      if(value===1){
        state.tips = {
          type:'success',
          message:'删除成功'
        }
      }else{
        state.tips = {
          type:'warning',
          message:'删除失败'
        }
      }
    },
  },
  actions:{
    getSystemCarList(ctx,payload){//获取车辆列表
      ctx.commit('changeLoading',true);
      if(!payload.carVin){
        ctx.commit('getSystemCarList',[]);
        ctx.commit('changeLoading',false);
      }else{
        axios.get(api.getCarList,{params:payload})
          .then(res=>{
            ctx.commit('changeLoading',false);
            ctx.commit('getSystemCarList',res.data.result);
          })
      }
    },
    deleteCar(ctx,payload){
      axios.get(api.insertCarDel,{params:{carId:payload.carId,userId:payload.userId}})
        .then(res=>{
          if(res.data.code===1){
            ctx.commit('changeDeleteStatus',1);
            ctx.commit('changeTips',1);
          }else{
            ctx.commit('changeDeleteStatus',-1);
            ctx.commit('changeTips',-1);
          }
        })
    },
    deleteActualCar(ctx,payload){
      axios.get(api.deleteCar,{params:{carId:payload.carId,userId:payload.userId}})
        .then(res=>{
          if(res.data.code===1){
            ctx.commit('changeDeleteStatus',1);
            ctx.commit('changeTips',1);
          }else{
            ctx.commit('changeDeleteStatus',-1);
            ctx.commit('changeTips',-1);
          }
        })
    }
  }
}
